﻿using System;
using System.Management;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Drawing.Printing;

namespace BACKOFFICE
{
    public partial class PosEquipment : DevExpress.XtraEditors.XtraUserControl
    {
        public PosEquipment()
        {
            InitializeComponent();
        }
        
        private void PosEquipment_Load(object sender, EventArgs e)
        {
            foreach (string printer in PrinterSettings.InstalledPrinters)
            {
                    GetPrinterInfo(printer);
            }
        }


        private static ManagementScope oManagementScope = null;
        public void GetPrinterInfo(string sPrinterName)
        {
            oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
            oManagementScope.Connect();

            SelectQuery oSelectQuery = new SelectQuery();
            oSelectQuery.QueryString = @"SELECT * FROM Win32_Printer 
	WHERE Name = '" + sPrinterName.Replace("\\", "\\\\") + "'";

            ManagementObjectSearcher oObjectSearcher =
               new ManagementObjectSearcher(oManagementScope, @oSelectQuery);
            ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();

            foreach (ManagementObject oItem in oObjectCollection)
            {

                ListViewItem item = new ListViewItem(oItem["Name"].ToString());
                item.SubItems.Add(oItem["Status"].ToString());

                listView2.Items.Add(item);


                //Console.WriteLine("Name : " + oItem["Name"].ToString());
                //Console.WriteLine("PortName : " + oItem["PortName"].ToString());
                //Console.WriteLine("DriverName : " + oItem["DriverName"].ToString());
                //Console.WriteLine("DeviceID : " + oItem["DeviceID"].ToString());
                //Console.WriteLine("Status : " + oItem["Status"].ToString());
                //Console.WriteLine("---------------------------------------------------------------");
            }
        }
    }
}
